Skip to content

Conversation

@Brackets-Coder
Copy link
Contributor

@Brackets-Coder Brackets-Coder commented Feb 25, 2025

Ammo Physics

A physics extension based on the ammo.js physics library, which is a direct port of the world-renowned C++ Bullet Physics SDK.

The goal is to provide feature-complete, advanced, and performant 3D physics in a simple-to-understand manner. This extension aims to be consistent with Box2D and Simple3D.

video.mp4

Task list:

  • Shapes
    • Boxes
    • Spheres
    • Cylinders
    • Cones
    • Capsules
    • Convex Hulls
    • Triangle Meshes
    • Compound bodies
    • There are some others (planes, heightfields), but I don't want to support these
  • Physical Materials (friction, restitution, etc.)
  • [ ] Constraints (All types)
  • Collision:
    • Collision Detection
    • Raycasting
    • Enable/disable collision response
  • Manual Impact forces (like "push with force" block in Box2D)
  • Bug fixing

Things I'm considering now or for a later update:

  • Vehicle support
  • Debug rendering support
  • Soft Bodies

Miscellaneous Notes Mainly for Moderators:

  • ChatGPT was used to assist and enhance the making of this extension, simply because I couldn't find good quality, coherent documentation of Ammo.js, and attempting to figure out how to use it via the developer inspector isn't fun. It did not write the code for me and I am still the main author of this extension. It just helped me learn Ammo.js. Hope this doesn't cause conflicts.
  • I'm not good at graphic design so if someone wants to make a banner/thumbnail that'd be great
  • Still have to incorporate Scratch.Cast where necessary, right now I'm just working on functionality though

Put an emoji (👍, 🚀) if you like this extension

@Brackets-Coder Brackets-Coder marked this pull request as draft February 25, 2025 22:31
@github-actions github-actions bot added the pr: new extension Pull requests that add a new extension label Feb 25, 2025
@WAYLIVES
Copy link

WAYLIVES commented Mar 4, 2025

Wow! It's very cool and useful for people like me)

@Brackets-Coder
Copy link
Contributor Author

Wow! It's very cool and useful for people like me)

Thank you! I've been making steady progress, but it probably won't be ready for a while (which is why this is a draft).

@Brackets-Coder Brackets-Coder changed the title Ammo Physics Ammo Physics (3D Physics Extension) Mar 19, 2025
@Brackets-Coder
Copy link
Contributor Author

Added partial support compound bodies - all child shape types.
Also working on convex and concave mesh support... it'll be a while.

@WAYLIVES
Copy link

wow

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Apr 2, 2025

Finally got convex hulls working 🥳 🎉

video.mp4

Still have to optimize and bug fix everything and add more features

@Brackets-Coder

This comment was marked as outdated.

@Xeltalliv

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder

This comment was marked as resolved.

@Xeltalliv

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as resolved.

@Brackets-Coder
Copy link
Contributor Author

@MasterThomas15 Your forces should be fixed in the latest commit, and I added a few new simulation utilities (get gravity/maxsubsteps and step simulation with user-provided parameters)

@Brackets-Coder

This comment was marked as resolved.

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Oct 21, 2025

The previous commit uses the new ESM stuff to do Scratch.external importing instead of pasting the entire libraries, this reduces the file size by like 89% (1000KB —> 108 KB) and makes it much easier to read

Tradeoff is that it doesn't seem to work in my version of the Desktop editor, which I don't think has been updated yet?

@wiktorlaskowski

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as resolved.

@wiktorlaskowski

This comment was marked as resolved.

@Brackets-Coder

This comment was marked as outdated.

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Nov 22, 2025

I'm not normally one to do this, but I think it'd be nice if I could have everyone review this PR just because it's so big.
I don't care how much time you take, I don't care if you don't do it, I understand it likely won't be merged, but as many eyes as possible would be very helpful.
Thanks so much everyone!

@Brackets-Coder Brackets-Coder requested a review from a team November 22, 2025 18:24
@LSPECTRONIZTAR
Copy link

When projects using this extension are packaged, will the packager embed the external dependencies into the packaged project so projects that use the extension can be used offline?

@GarboMuffin
Copy link
Member

if this is merged, projects using it will work fine offline

before then, no currently the packager does not know how to convert all the Scratch.external.* into an inline thing on its own yet

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Dec 3, 2025

if this is merged, projects using it will work fine offline

before then, no currently the packager does not know how to convert all the Scratch.external.* into an inline thing on its own yet

Wait so you mean when it's merged, the builder will convert it into a data url, but the internet url currently in the extension can't be packaged?

@Brackets-Coder
Copy link
Contributor Author

oops wrong button

@Brackets-Coder Brackets-Coder reopened this Dec 3, 2025
@Brackets-Coder
Copy link
Contributor Author

Also validate is yelling at me

extensions/MasterMath/AmmoPhysics.js: Error: https://raw.githubusercontent.com/Brackets-Coder/AmmoPhysics/refs/heads/main/dependencies/ammo.min.js is not a known immutable URL. npm packages need to be pinned to an exact version. Git repositories need to be pinned to an exact commit hash. Extend isImmutableURL() in development/dependency-management.js if this is false positive.

@GarboMuffin
Copy link
Member

it's telling you to use a specific commit and not just whatever is on the main branch

@Brackets-Coder
Copy link
Contributor Author

Brackets-Coder commented Dec 6, 2025

I have a few trivial inquiries for any who may be able to help:

  1. The URL of the ammo physics library points to a custom build on my repository. Is this acceptable, or do I need to use a different one? I didn't want to use the one on NPM because it isn't as optimized.
  2. Some of the blocks use third-party icons found in the Blender source code. I've added a link to where I found them, but do I also need to include Blender's license in the code?

The more complex questions

  1. The extension automatically clears all bodies and rays and resets the world upon the project starting. This is used as a memory management tool, but will some users find it unintuitive? Some rely on project data persisting even after green flag click and there's a "reset world" block that does the same thing. Do I need to add some kind of toggle to enable or disable the automatic resetting?
  2. With the custom build, WebAssembly and another build flag enables scalable memory. This prevents a crashing bug and allows projects to have very large-scale physics simulations, but some browsers may automatically reload the page or the page may crash if it uses too much memory. Additionally, I have some concerns about an undiscovered memory leak in the code (although I have been very careful with my memory management), because once in a blue moon I'll see a Turbowarp warning that the renderer process crashed, and the page freezes. This is rare and only occurs in extreme scenarios, but is it a dealbreaker and does it need to be fixed prior to merging?

@Meehdrescher
Copy link

About 3: From the point of view of a potential user of your extension (still need to test if it is viable for my projects but it looks really nice already), I would definitely like to have the flexibility of being able to turn off automatic resetting, I'm a big fan of having options for everything and I'm probably not the only one

@Brackets-Coder
Copy link
Contributor Author

Noted

@Brackets-Coder
Copy link
Contributor Author

I was also previously considering putting an "Advanced Options" button at the bottom of the pallet that would reveal additional blocks (such as visual debug rendering, but this has since been scrapped due to scope). I could still do this for a few smaller options

@Meehdrescher
Copy link

Also, for me (on the newest version, git cloned desktop with NodeJS and unrestricted mode), the current version in your repo throws an error when loading: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'evalAndReturn') at 21:39 at 2584:3

@GarboMuffin
Copy link
Member

that would mean your vm is outdated

@Brackets-Coder
Copy link
Contributor Author

Also, for me (on the newest version, git cloned desktop with NodeJS and unrestricted mode), the current version in your repo throws an error when loading: Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'evalAndReturn') at 21:39 at 2584:3

The latest version of the extension makes use of the relatively new external dependency features. It's working for me on the latest version of Turbowarp desktop from the Mac app store, but if it's not working for you I'd recommend just using the web editor as that's almost always up to date

@Meehdrescher
Copy link

that would mean your vm is outdated

Is that actually a possible issue, even if I just cloned everything into a completely new environment about 10 minutes ago?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: new extension Pull requests that add a new extension

Projects

None yet

Development

Successfully merging this pull request may close these issues.